package wangwenjun.phase2.concurrencypattern.singlethreadexecution.demo01;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/**
 * @author ChangLiang
 * @date 2020/6/12
 */
public class AppTest {

    @Test
    @DisplayName("test V1")
    public void test() throws InterruptedException {
        final FlightSecurityV1 flightSecurity = new FlightSecurityV1();
        PassengerV1 passengers01 = new PassengerV1(flightSecurity, "A123456", "AF123456");
        passengers01.start();
        PassengerV1 passengers02 = new PassengerV1(flightSecurity, "B123456", "BF123456");
        passengers02.start();
        PassengerV1 passengers03 = new PassengerV1(flightSecurity, "C123456", "CF123456");
        passengers03.start();
        PassengerV1 passengers04 = new PassengerV1(flightSecurity, "D123456", "DF123456");
        passengers04.start();

        passengers01.join();
        passengers02.join();
        passengers03.join();
        passengers04.join();
    }

    @Test
    @DisplayName("test V2 -- synchronized")
    public void test2() throws InterruptedException {
        final FlightSecurityV2 flightSecurity = new FlightSecurityV2();
        PassengerV2 passengers01 = new PassengerV2(flightSecurity, "A123456", "AF123456");
        passengers01.start();
        PassengerV2 passengers02 = new PassengerV2(flightSecurity, "B123456", "BF123456");
        passengers02.start();
        PassengerV2 passengers03 = new PassengerV2(flightSecurity, "C123456", "CF123456");
        passengers03.start();
        PassengerV2 passengers04 = new PassengerV2(flightSecurity, "D123456", "DF123456");
        passengers04.start();

        passengers01.join();
        passengers02.join();
        passengers03.join();
        passengers04.join();
    }
}
